How to make requests or pass data from a form to a URL
In this article, you will learn about a new way to pass data from a form to a remote URL - Webhook. Using a webhook, you can exchange information with third-party resources. For example, make a call to your individual URL or send form data to this address.
Webhooks allow you to integrate workflows between systems/services/applications (including calls between different projects within a QuintaDB system). This is a great help to organize your business processes, and we are sure that you will find many ways to take advantage of webhooks.
Content:
Note: Webhooks are primarily intended to communicate with external services. Inside the QuintaDB system, it's enough to use standard tools such as Relationship and Subform.
You can use Webhook with:
- Action field;
- Conditional Actions module.
Let's see how it works. As an example, we will use the Content Agency application, which can be installed on the Application page.
Also, we will use the webhook.site service for the demonstration. This can be any URL you want.
Copy your unique URL. Now let's open the Articles form in our Content Agency application.
Consider the first way - the Action field:
1. Add the "Action" field to the form (you can find it in the "Additional" tab);
2. Open the field editing page. Go to the "Tasks" tab or select the "What to do" item;
3. Create a new task. Select the Webhook task type;
4. Go to the "Settings" section.
Here you need to insert the URL (in this example, this will be the URL received on the webhook.site service).
Select the data transfer method (GET, POST, PATCH, DELETE). For more information about data transfer methods, read the API documentation.
Select the Content-Type (multipart/form-data, application/x-www-form-urlencoded, application/json).
In this example, we use the POST method and the application/json type.
5. In the "Request headers" section, you can add a header and data for authorization (optional);
6. In the "Request parameters" section, you need to specify the name of the parameter and select fields from the form:
Also, you can choose Custom from the list. Thus, you will pass an individual parameter, instead of a value from the form.
Please note: To pass the current record owner, you need to add a custom parameter "copy_owners" with any value (for example "1"), in the "Request parameters" section:
7. Click the "Create" button.
8. Сlick on "Action" in the table for testing:
9. Check the result of data transfer on the Webhook service:
All data has been successfully transferred.
Now let's look at another method by Conditional actions module.
We will use the same form.
1. Go to the Form Builder and open the Actions tab. Create a new conditional action.
2. Select a criterion for performing the action (for example, the Title field is not empty).
Please note: in this case, there is no transition to another page, and all data is stored in parallel in your QuintaDB database.
3. Click on the "Edit" button after creating the action:
4. You need to configure the webhook in the same way as the settings in the Action field. Click on the "Edit" button next to the "Webhook" action.
Please note: you will use an API call from your account resources every time you transfer data.